/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution1 {
    public boolean evaluateTree(TreeNode root) {
        if(root.left==null) return root.val==1;
        boolean l= evaluateTree(root.left);
        boolean r= evaluateTree(root.right);
        if(root.val==2) return l||r;
        else return l&&r;




    }
}


/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution2{
    public int sumNumbers(TreeNode root) {
        return dfs(root,0);



    }
    public int dfs(TreeNode root,int ret){

        if(root==null) return 0;

        ret=ret*10+root.val;
        if(root.left==null&&root.right==null) return ret;

        int l=dfs(root.left,ret);
        int r=dfs(root.right,ret);

        return l+r;



    }
}